using System;
using System.Web;
using System.Web.UI;

namespace Sedna.Core.Controls.Support.Javascript
{
	public class ScriptTag
	{
		private string scriptClass;
		private string src;
		private string body;

		public string ScriptClass
		{
			get { return scriptClass; }
			set { scriptClass = value; }
		}

		public string Src
		{
			get { return src; }
			set { src = value; }
		}

		public string Body
		{
			get { return body; }
			set { body = value; }
		}

		public override string ToString()
		{
			string attributes=String.Empty;
			attributes+=CreateAttribute("src", src);
			attributes+=CreateAttribute("scriptClass", scriptClass);

			return String.Format("<script language=\"javascript\" type=\"text/javascript\"{0}>{1}</script>", attributes, body);
		}

		public void Render(HtmlTextWriter writer)
		{
			writer.Write(this.ToString());
		}

		private string CreateAttribute(string name, string value)
		{
			if (value==null)
			{
				return String.Empty;
			}	
			return String.Format(" {0}=\"{1}\" ", name, HttpUtility.HtmlAttributeEncode(value));
		}
	}
}
